package com.xianyu.us.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.xianyu.us.common.vo.PageObject;
import com.xianyu.us.pojo.entity.UsGoods;
import com.xianyu.us.pojo.vo.JsonResult;
import com.xianyu.us.service.UsGoodsService;

/**
 * 发布商品相关入口
 * @author lixilin
 *
 */
@RequestMapping("/goods/")
@Controller
public class UsGoodsController {
	@Autowired
	private UsGoodsService usGoodsService;
	@RequestMapping("doDeleteById")
	@ResponseBody
	public JsonResult doDeleteById(Integer id) {
		usGoodsService.deleteById(id);
		return new JsonResult("delete ok");
	}
	
	@RequestMapping("doUpdateById")
	@ResponseBody
	public JsonResult doUpdateById(UsGoods entity) {
		usGoodsService.updateById(entity);
		return new JsonResult("insert ok");
	}
	
	@RequestMapping("doFindByUserId")
	@ResponseBody
	public JsonResult doFindByUserId(Integer useId,Integer pageCurrent) {
		PageObject<UsGoods> object = usGoodsService.findByUserId(useId, pageCurrent);
		return new JsonResult(object);
	}
	@RequestMapping("doFindById")
	@ResponseBody
	public JsonResult doFindById(Integer id) {
		List<UsGoods> object = usGoodsService.findById(id);
		return new JsonResult(object);
	}
	
	@RequestMapping("doFindObject")
	@ResponseBody
	public JsonResult doFindObjects(String content,Integer pageCurrent) {
		PageObject<UsGoods> object = usGoodsService.finObject(content, pageCurrent);
		System.out.println(object);
		return new JsonResult(object);
	}
	
	/**
	 *
	 * @param entity
	 * @param file
	 * @return
	 */

	@RequestMapping("doSaveGoods")
	@ResponseBody
	public JsonResult doSaveObject(UsGoods entity,MultipartFile... file){
		usGoodsService.insertGoods(entity,file);
		return new JsonResult("save ok");
	}

}
		

	
	

